//
//  LZCouponManagerListDetailViewController.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/21.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCouponManagerListDetailViewController.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "LZCouponManagerListDetailContentCell.h"
#import "LZCouponManagerListDetailTopTitleCell.h"
#import "LZCouponManagerListDetailTagsCell.h"
#import "LZCouponManagerListDetailSectionView.h"
#import "LZCustomPlayerView.h"
#import "LZPlayVideoManager.h"
#import "Masonry.h"
#import "LZCouponPresenter.h"
#import "LZCouponListCouponDetailModel.h"
#import "LZCouponModel.h"
#import "LZGrouponModel.h"
#import "LZDateFormatterManager.h"
#import "LZCouponListCellPresenter.h"
#import "LZCreatePromotionViewController.h"
#import "LZCouponListModel.h"
#import "UIImageView+WebCache.h"

static NSString *kTitleCell = @"titlecell";
static NSString *kTagsCell = @"tagscell";
static NSString *kContentCell = @"contentcell";
static CGFloat kSectionDefaultHeight = 64.0;


@interface LZCouponManagerListDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) LZCustomPlayerView *playerView;
@property (nonatomic, strong) UIView *videoBgView;
@property (nonatomic, strong) UIImageView *videoCoverImage;

@property (assign, nonatomic) BOOL couponSectionIsOpen;
@property (assign, nonatomic) BOOL groupSectionIsOpen;

@property (strong, nonatomic) LZCouponManagerListDetailSectionView *couponSectionView;
@property (strong, nonatomic) LZCouponManagerListDetailSectionView *groupSectionView;
@property (strong, nonatomic) NSArray *couponCellNameArr;
@property (strong, nonatomic) NSArray *groupCellNameArr;
@property (nonatomic, strong) LZCouponPresenter *couponPresenter;
@property (nonatomic, strong) LZCouponListCouponDetailModel *dataModel;
@property (weak, nonatomic) IBOutlet UIButton *leftFootBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightFootBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftFootBtnWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomToSuperviewConstraint;
@property (nonatomic, strong) LZCouponListCellPresenter *couponListCellPresenter;

@end

@implementation LZCouponManagerListDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.umLogPageViewName = @"优惠管理-优惠列表详情页面";
    
    [self configureUI];
    
    [self configureData];
    
    [self registerCellAndSectionView];
    
    [self getDetailData];
}

- (void)dealloc
{
    [self releasePlayViewRAM];
}

#pragma mark -
#pragma mark private
- (IBAction)rightFootBtnAction:(UIButton *)sender {
    
    WS(wSelf);
    if (self.rightFootBtn.tag == kCouponList_edit) {
        
        LZCreatePromotionViewController *vc = [[LZCreatePromotionViewController alloc] init];
        vc.couponListModel = [self.couponListModel copy];
        vc.eventCode = kCouponList_edit;
        vc.isComeFromCouponDetailVC = YES;
        [vc setOperationCouponStateSuccessBlock:^(CouponListEventCode eventCode, LZCouponListModel *returnModel) {
            if (wSelf.operationCouponStateSuccessBlock) {
                wSelf.operationCouponStateSuccessBlock(eventCode, returnModel);
            }
        }];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}

- (IBAction)leftFootBtnAction:(UIButton *)sender {
    
    WS(wSelf);
    switch (self.leftFootBtn.tag) {
        case kCouponList_submit:{//提交审核
            [self operationCouponWithCouponListEventCode:kCouponList_submit];
        }
            break;
        case kCouponList_publish:{//发布
            [self operationCouponWithCouponListEventCode:kCouponList_publish];
        }
            break;
        case kCouponList_finish:{//下线优惠
            [self operationCouponWithCouponListEventCode:kCouponList_finish];
        }
            break;
        case kCouponList_copy:{
            LZCreatePromotionViewController *vc = [[LZCreatePromotionViewController alloc] init];
            vc.couponListModel = [self.couponListModel copy];
            vc.eventCode = kCouponList_copy;
            vc.isComeFromCouponDetailVC = YES;
            [vc setOperationCouponStateSuccessBlock:^(CouponListEventCode eventCode, LZCouponListModel *returnModel) {
                if (wSelf.operationCouponStateSuccessBlock) {
                    wSelf.operationCouponStateSuccessBlock(eventCode, nil);
                }
            }];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case kCouponList_edit:{
            LZCreatePromotionViewController *vc = [[LZCreatePromotionViewController alloc] init];
            vc.couponListModel = [self.couponListModel copy];
            vc.eventCode = kCouponList_edit;
            vc.isComeFromCouponDetailVC = YES;
            [vc setOperationCouponStateSuccessBlock:^(CouponListEventCode eventCode, LZCouponListModel *returnModel) {
                if (wSelf.operationCouponStateSuccessBlock) {
                    wSelf.operationCouponStateSuccessBlock(eventCode, returnModel);
                }
            }];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
    
}

- (void)operationCouponWithCouponListEventCode:(CouponListEventCode)eventCode
{
    WS(wSelf);
    [self.couponListCellPresenter dealClickCouponOperationButtonCode:eventCode andModel:self.dataModel isInCouponDetailVC:YES operationSuccess:^{
        
        if (wSelf.operationCouponStateSuccessBlock) {
            wSelf.operationCouponStateSuccessBlock(eventCode,nil);
        }
        
        [wSelf.navigationController popViewControllerAnimated:YES];
        
    } Failure:^(NSString *error) {
        
    }];
}

- (void)getDetailData
{
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:NO];
    WS(wself);
    [self.couponPresenter getCouponDetailWithCouponID:self.couponListModel.couponId ResultSuccess:^(LZCouponListCouponDetailModel *couponModel) {
        
        wself.dataModel = couponModel;
        
        [wself.videoCoverImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,couponModel.videoPhoto]] placeholderImage:[UIImage imageNamed:@"videoCoverImg"]];
        
        [wself.tableView reloadData];
        
        [wself playVideo];
        
        [wself stopLoadingViewForView:wself.view];
        
    } Failure:^(NSString *fail) {
        [wself stopLoadingViewForView:wself.view];
        DLog(@"%@",fail);
    }];
}

- (void)clickCouponSectionBtn
{
    _couponSectionIsOpen = !_couponSectionIsOpen;
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
}

- (void)clickGroupSectionBtn
{
    _groupSectionIsOpen = !_groupSectionIsOpen;
    if (self.dataModel.coupons.couponsName.length > 0) {
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationFade];
    }else{
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
    }
    
}

- (void)playVideo
{
    [[LZPlayVideoManager shareManager] playVideoWithBgView:self.videoBgView playerView:self.playerView videoURL:self.dataModel.videoUrl videoID:nil playCountAddBlock:^(NSInteger totleCount) {
        
    }];
}

/**
 离开页面,释放播放器内存
 */
- (void)releasePlayViewRAM
{
    [self.playerView stopAction];
    _playerView = nil;
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
}

#pragma mark -
#pragma mark configure UI
- (void)configureUI
{
    GET_SCREEN_WIDTH(viewWidth);
    switch (self.couponListModel.state) {
        case kCouponDetail_saved:{//已经保存
            [self.leftFootBtn setTitle:LZLocalizedString(@"submit_min", nil) forState:UIControlStateNormal];
            self.leftFootBtnWidth.constant = viewWidth/2;
            self.leftFootBtn.tag = kCouponList_submit;
            
            [self.rightFootBtn setTitle:LZLocalizedString(@"edit_min", nil) forState:UIControlStateNormal];
            self.rightFootBtn.tag = kCouponList_edit;
        }
            break;
        case kCouponDetail_rejected:{//已经驳回
            [self.leftFootBtn setTitle:LZLocalizedString(@"edit_min", nil) forState:UIControlStateNormal];
            self.leftFootBtnWidth.constant = viewWidth;
            self.leftFootBtn.tag = kCouponList_edit;
            self.rightFootBtn.hidden = YES;
        }
            break;
        case kCouponDetail_waitApproval:{//等待审核
            self.leftFootBtn.hidden = YES;
            self.rightFootBtn.hidden = YES;
            self.tableViewBottomToSuperviewConstraint.constant = 0;
        }
            break;
        case kCouponDetail_approved:{//审核通过
            [self.leftFootBtn setTitle:LZLocalizedString(@"publish_min", nil) forState:UIControlStateNormal];
            self.leftFootBtnWidth.constant = viewWidth/2;
            self.leftFootBtn.tag = kCouponList_publish;
            
            [self.rightFootBtn setTitle:LZLocalizedString(@"edit_min", nil) forState:UIControlStateNormal];
            self.rightFootBtn.tag = kCouponList_edit;
        }
            break;
        case kCouponDetail_published:{//已经发布
            [self.leftFootBtn setTitle:LZLocalizedString(@"finish_min", nil) forState:UIControlStateNormal];
            self.leftFootBtnWidth.constant = viewWidth;
            self.leftFootBtn.tag = kCouponList_finish;
            self.rightFootBtn.hidden = YES;
            
        }
            break;
        case kCouponDetail_finished:{//已经下线
            [self.leftFootBtn setTitle:LZLocalizedString(@"copy_min", nil) forState:UIControlStateNormal];
            self.leftFootBtnWidth.constant = viewWidth;
            self.leftFootBtn.tag = kCouponList_copy;
            self.rightFootBtn.hidden = YES;
            
        }
            break;
            
        default:{
            self.leftFootBtn.hidden = YES;
            self.rightFootBtn.hidden = YES;
            self.tableViewBottomToSuperviewConstraint.constant = 0;
        }
            break;
    }
}

- (void)configureData
{
    _couponSectionIsOpen = YES;
    _groupSectionIsOpen = YES;
    _couponPresenter = [[LZCouponPresenter alloc] init];
    _couponListCellPresenter = [[LZCouponListCellPresenter alloc] init];
    _couponCellNameArr = @[LZLocalizedString(@"name", nil),
                           LZLocalizedString(@"coupon_amount_range", nil),
                           LZLocalizedString(@"conditions", nil),
                           LZLocalizedString(@"coupons_to_issue", nil),
                           LZLocalizedString(@"valid_from_to", nil),
                           LZLocalizedString(@"coupon_not_valid_on", nil),
                           LZLocalizedString(@"everyday_valid", nil),
                           LZLocalizedString(@"need_to_book_in_advance", nil),
                           LZLocalizedString(@"other_conditions", nil)
                           ];
    
    _groupCellNameArr = @[LZLocalizedString(@"name", nil),
                          LZLocalizedString(@"object_of_the_group_order", nil),
                          LZLocalizedString(@"original_price", nil),
                          LZLocalizedString(@"group_order_price", nil),
                          LZLocalizedString(@"required_people", nil),
                          LZLocalizedString(@"finish_time", nil),
                          LZLocalizedString(@"expiration_date", nil),
                          LZLocalizedString(@"coupon_not_valid_on", nil),
                          LZLocalizedString(@"everyday_valid", nil),
                          LZLocalizedString(@"need_to_book_in_advance", nil),
                          LZLocalizedString(@"other_conditions", nil)
                          ];
}

- (void)registerCellAndSectionView
{
    [self.tableView registerNib:[UINib nibWithNibName:@"LZCouponManagerListDetailContentCell" bundle:nil] forCellReuseIdentifier:kContentCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZCouponManagerListDetailTopTitleCell" bundle:nil] forCellReuseIdentifier:kTitleCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZCouponManagerListDetailTagsCell" bundle:nil] forCellReuseIdentifier:kTagsCell];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.videoBgView addSubview:self.videoCoverImage];
    self.tableView.tableHeaderView = self.videoBgView;
    
}

#pragma mark -
#pragma mark tableview delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 4;
            break;
        case 1:{//当优惠券团购都有时,这里是优惠券,但是当只有两者的时候,要判断是否没有优惠券
            if (self.dataModel.coupons.couponsName.length > 0) {
                return _couponSectionIsOpen ? _couponCellNameArr.count : 0;
            }else if (self.dataModel.groupon.grouponName.length > 0 && self.dataModel.coupons.couponsName.length == 0){
                return _groupSectionIsOpen ? _groupCellNameArr.count : 0;
            }
        }
            break;
        case 2:
            return _groupSectionIsOpen ? _groupCellNameArr.count : 0;
            break;
            
        default:
            break;
    }
    
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (self.dataModel.coupons.couponsName.length > 0 && self.dataModel.groupon.grouponName.length > 0) {
        return 3;
    }else if (self.dataModel.coupons.couponsName.length == 0 && self.dataModel.groupon.grouponName.length == 0){
        return 1;
    }else{
        return 2;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else if (section == 1){
        return kSectionDefaultHeight;
    }else{
        return kSectionDefaultHeight;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        return 0;
    }
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    bgView.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
    
    return bgView;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kSectionDefaultHeight)];
        bgView.backgroundColor = [UIColor whiteColor];
        if (self.dataModel.coupons.couponsName.length > 0) {//如有有优惠
            
            self.couponSectionView.nameLabel.text = LZLocalizedString(@"coupon", nil);
            [bgView addSubview:self.couponSectionView];
            
            [self.couponSectionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(bgView);
            }];
            [self.couponSectionView setLeftImgStateIsSelect:YES];
            [self.couponSectionView setRightArrowImgStateIsSelect:_couponSectionIsOpen];
            
        }else if (self.dataModel.groupon.grouponName.length > 0 && self.dataModel.coupons.couponsName.length == 0){//如果没有优惠,只有团购
            
            self.groupSectionView.nameLabel.text = LZLocalizedString(@"group_order", nil);
            [bgView addSubview:self.groupSectionView];
            
            [self.groupSectionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(bgView);
            }];
            
            [self.groupSectionView setLeftImgStateIsSelect:YES];
            [self.groupSectionView setRightArrowImgStateIsSelect:_groupSectionIsOpen];
        }
        
        return bgView;
        
    }else if (section == 2){
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kSectionDefaultHeight)];
        bgView.backgroundColor = [UIColor whiteColor];
        self.groupSectionView.nameLabel.text = LZLocalizedString(@"group_order", nil);
        [bgView addSubview:self.groupSectionView];
        
        [self.groupSectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(bgView);
        }];
        
        [self.groupSectionView setLeftImgStateIsSelect:YES];
        [self.groupSectionView setRightArrowImgStateIsSelect:_groupSectionIsOpen];
        
        return bgView;
    }
    
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return [self returnTopSectionCellHeightWithIndexPath:indexPath withTableView:tableView];
        
    }else if(indexPath.section == 1){
        if (self.dataModel.coupons.couponsName.length > 0) {
            
            return [self returnCouponCellHeightWithIndexPath:indexPath withTableView:tableView];
        }else if (self.dataModel.groupon.grouponName.length > 0 && self.dataModel.coupons.couponsName.length == 0){
            
            return [self returnGroupCellHeightWithIndexPath:indexPath withTable:tableView];
        }
        
    }else if (indexPath.section == 2){
        
        return [self returnGroupCellHeightWithIndexPath:indexPath withTable:tableView];
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        switch (indexPath.row) {
            case 0:{
                LZCouponManagerListDetailTopTitleCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kTitleCell];
                [cellTemp loadContentText:self.dataModel.promotionTitle];
                
                return cellTemp;
                
            }
                break;
            case 1:{
                LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
                [cellTemp setCellName:LZLocalizedString(@"ingredients_components", nil) cellContent:self.dataModel.promotionFood];
                
                return cellTemp;
            }
                break;
            case 2:{
                LZCouponManagerListDetailTagsCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kTagsCell];
                [cellTemp loadTagsContent:self.dataModel.tag];
                
                return cellTemp;
            }
                break;
            case 3:{
                LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
                [cellTemp setCellName:LZLocalizedString(@"description", nil) cellContent:self.dataModel.promotionFood];
                
                return cellTemp;
            }
                break;
            default:
                break;
        }
        
        return nil;
        
    }else if(indexPath.section == 1){
        
        if (self.dataModel.coupons.couponsName.length > 0) {
            
            return [self returnCouponCellWithIndexpath:indexPath withTable:tableView];
            
        }else if (self.dataModel.groupon.grouponName.length > 0 && self.dataModel.coupons.couponsName.length == 0){
            
            return [self returnGroupCellWithIndexpath:indexPath withTable:tableView];
        }
        
    }else if (indexPath.section == 2){
        
        return [self returnGroupCellWithIndexpath:indexPath withTable:tableView];
    }
    
    return nil;
}

#pragma mark -
#pragma mark tablveiw 协议操作
- (CGFloat)returnTopSectionCellHeightWithIndexPath:(NSIndexPath *)indexP withTableView:(UITableView *)tableView
{
    WS(wSelf);
    switch (indexP.row) {
        case 0:{//名字
            return [tableView fd_heightForCellWithIdentifier:kTitleCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailTopTitleCell *cellTemp = (LZCouponManagerListDetailTopTitleCell *)cell;
                [cellTemp loadContentText:wSelf.dataModel.promotionTitle];
                
            }];
        }
            break;
        case 1:{//食材
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:LZLocalizedString(@"ingredients_components", nil) cellContent:wSelf.dataModel.promotionFood];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 2:{//tags
            return [tableView fd_heightForCellWithIdentifier:kTagsCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailTagsCell *cellTemp = (LZCouponManagerListDetailTagsCell *)cell;
                [cellTemp loadTagsContent:wSelf.dataModel.tag];
            }];
        }
            break;
        case 3:{//简介
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:LZLocalizedString(@"description", nil) cellContent:[NSString stringWithFormat:@"%ld",(long)wSelf.dataModel.coupons.couponsTotalCount]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        default:
            break;
    }
    
    return 0;
    
}
- (CGFloat)returnCouponCellHeightWithIndexPath:(NSIndexPath *)indexP withTableView:(UITableView *)tableView
{
    WS(wSelf);
    switch (indexP.row) {
        case 0:{//优惠券名字
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:wSelf.dataModel.coupons.couponsName];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 1:{//金额
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",wSelf.dataModel.coupons.couponsMoney]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 2:{//使用条件
            if (wSelf.dataModel.coupons.couponsUseConditions.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:wSelf.dataModel.coupons.couponsUseConditions];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 3:{//发放张数
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%ld",(long)wSelf.dataModel.coupons.couponsTotalCount]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 4:{//时间
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.coupons.couponsStartTime],[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.coupons.couponsEndTime]]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 5:{//列外时间
            if (wSelf.dataModel.coupons.couponsExceptTime.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:wSelf.dataModel.coupons.couponsExceptTime];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 6:{//每天运营时间
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",wSelf.dataModel.coupons.couponsStartDaytime,wSelf.dataModel.coupons.couponsEndDaytime]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 7:{//预约提醒
            if (wSelf.dataModel.coupons.couponsRemindAppoint.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:wSelf.dataModel.coupons.couponsRemindAppoint];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 8:{//规则提醒
            if (wSelf.dataModel.coupons.couponsRemindRule.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.couponCellNameArr[indexP.row] cellContent:wSelf.dataModel.coupons.couponsRemindRule];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
            
        default:
            break;
    }
    
    return 0;
}

- (LZCouponManagerListDetailContentCell *)returnCouponCellWithIndexpath:(NSIndexPath *)indexP withTable:(UITableView *)tableView
{
    switch (indexP.row) {
        case 0:{//优惠全名字
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:self.dataModel.coupons.couponsName];
            
            return cellTemp;
        }
            break;
        case 1:{//价格
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",self.dataModel.coupons.couponsMoney]];
            
            return cellTemp;
        }
            break;
        case 2:{//使用条件
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:self.dataModel.coupons.couponsUseConditions];
            
            return cellTemp;
        }
            break;
        case 3:{//发放张数
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%ld",(long)self.dataModel.coupons.couponsTotalCount]];
            
            return cellTemp;
        }
            break;
        case 4:{//时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.coupons.couponsStartTime],[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.coupons.couponsEndTime]]];
            
            return cellTemp;
        }
            break;
        case 5:{//例外时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:self.dataModel.coupons.couponsExceptTime];
            
            return cellTemp;
        }
            break;
        case 6:{//每天营业时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",self.dataModel.coupons.couponsStartDaytime,self.dataModel.coupons.couponsEndDaytime]];
            
            return cellTemp;
        }
            break;
        case 7:{//预约提醒
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:self.dataModel.coupons.couponsRemindAppoint];
            
            return cellTemp;
        }
            break;
        case 8:{//规则提醒
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.couponCellNameArr[indexP.row] cellContent:self.dataModel.coupons.couponsRemindRule];
            
            return cellTemp;
        }
            break;
            
        default:
            break;
    }
    
    return nil;
}

- (CGFloat)returnGroupCellHeightWithIndexPath:(NSIndexPath *)indexP withTable:(UITableView *)tableView
{
    WS(wSelf);
    switch (indexP.row) {//团购名称
        case 0:{
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:wSelf.dataModel.groupon.grouponName];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 1:{//团购菜品
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:wSelf.dataModel.groupon.grouponFoods];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 2:{//原价
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",wSelf.dataModel.groupon.grouponBeforeCost]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 3:{//团购价格
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",wSelf.dataModel.groupon.grouponAfterCost]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 4:{//人数要求
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%ld",(long)wSelf.dataModel.groupon.grouponCount]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 5:{//团购结束时间
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.groupon.grouponEndTime]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 6:{//团购使用结束时间
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.groupon.grouponDeadline]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 7:{//团购列外时间
            if (wSelf.dataModel.groupon.grouponExceptTime.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:wSelf.dataModel.groupon.grouponExceptTime];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 8:{//每天工作时间
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",wSelf.dataModel.groupon.grouponStartDaytime,wSelf.dataModel.groupon.grouponEndDaytime]];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 9:{//预约提醒
            if (wSelf.dataModel.groupon.grouponRemindAppoint.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:wSelf.dataModel.groupon.grouponRemindAppoint];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
        case 10:{//规则提醒
            if (wSelf.dataModel.groupon.grouponRemindRule.length == 0) {
                return 0;
            }
            return [tableView fd_heightForCellWithIdentifier:kContentCell cacheByIndexPath:indexP configuration:^(id cell) {
                LZCouponManagerListDetailContentCell *cellTemp = (LZCouponManagerListDetailContentCell *)cell;
                [cellTemp setCellName:wSelf.groupCellNameArr[indexP.row] cellContent:wSelf.dataModel.groupon.grouponRemindRule];
                [cellTemp getCellContentLabel].preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
            }];
        }
            break;
            
        default:
            break;
    }
    
    return 0;
}

- (LZCouponManagerListDetailContentCell *)returnGroupCellWithIndexpath:(NSIndexPath *)indexP withTable:(UITableView *)tableView
{
    switch (indexP.row) {//团购名称
        case 0:{
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:self.dataModel.groupon.grouponName];
            
            return cellTemp;
        }
            break;
        case 1:{//团购菜品
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:self.dataModel.groupon.grouponFoods];
            
            return cellTemp;
        }
            break;
        case 2:{//原价
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",self.dataModel.groupon.grouponBeforeCost]];
            
            return cellTemp;
        }
            break;
        case 3:{//团购价格
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%.3fBHD",self.dataModel.groupon.grouponAfterCost]];
            
            return cellTemp;
        }
            break;
        case 4:{//人数要求
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%ld",(long)self.dataModel.groupon.grouponCount]];
            
            return cellTemp;
        }
            break;
        case 5:{//团购结束时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.groupon.grouponEndTime]];
            
            return cellTemp;
        }
            break;
        case 6:{//团购使用结束时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.groupon.grouponDeadline]];
            
            return cellTemp;
        }
            break;
        case 7:{//团购列外时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:self.dataModel.groupon.grouponExceptTime];
            
            return cellTemp;
        }
            break;
        case 8:{//每天工作时间
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:[NSString stringWithFormat:@"%@~%@",self.dataModel.groupon.grouponStartDaytime,self.dataModel.groupon.grouponEndDaytime]];
            
            return cellTemp;
        }
            break;
        case 9:{//预约提醒
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:self.dataModel.groupon.grouponRemindAppoint];
            
            return cellTemp;
        }
            break;
        case 10:{//规则提醒
            LZCouponManagerListDetailContentCell *cellTemp = [tableView dequeueReusableCellWithIdentifier:kContentCell];
            [cellTemp setCellName:self.groupCellNameArr[indexP.row] cellContent:self.dataModel.groupon.grouponRemindRule];
            
            return cellTemp;
        }
            break;
            
        default:
            break;
    }
    
    return nil;
}

#pragma mark -
#pragma mark 初始化
- (LZCouponManagerListDetailSectionView *)couponSectionView
{
    if (!_couponSectionView) {
        _couponSectionView = [[NSBundle mainBundle] loadNibNamed:@"LZCouponManagerListDetailSectionView" owner:self options:nil].lastObject;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCouponSectionBtn)];
        [[_couponSectionView getClickAreaView] addGestureRecognizer:tap];
    }
    
    return _couponSectionView;
}

- (LZCouponManagerListDetailSectionView *)groupSectionView
{
    if (!_groupSectionView) {
        _groupSectionView = [[NSBundle mainBundle] loadNibNamed:@"LZCouponManagerListDetailSectionView" owner:self options:nil].lastObject;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickGroupSectionBtn)];
        [[_groupSectionView getClickAreaView] addGestureRecognizer:tap];
    }
    
    return  _groupSectionView;
}

- (UIView *)videoBgView
{
    if (!_videoBgView) {
        _videoBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
        _videoBgView.backgroundColor = [UIColor blackColor];;
        
    }
    
    return _videoBgView;
}

- (UIImageView *)videoCoverImage
{
    if (!_videoCoverImage) {
        _videoCoverImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
        _videoCoverImage.backgroundColor = [UIColor blackColor];
    }
    
    return _videoCoverImage;
}

- (LZCustomPlayerView *)playerView
{
    if (!_playerView) {
        _playerView = [[LZCustomPlayerView alloc] init];
        _playerView.playCircle = NO;
    }
    
    return _playerView;
}

@end






